package com.sgb.merchant.viewmodel;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.lifecycle.MutableLiveData;

import com.sgb.link.entity.merchant.ApplyEntity;
import com.sgb.merchant.api.MerchantsNet;
import com.sgb.net.entity.ListResponse;
import com.swgk.core.base.api.ICallBack;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.common.base.BaseViewModel;
import com.swgk.core.dialog.DialogHelper;
import com.swgk.core.util.MToast;

import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class SelfApplyViewModel extends BaseViewModel {
   public MutableLiveData<List<ApplyEntity>> ldData=new MutableLiveData<>();
    private int pageNum = 1;
    public MutableLiveData<Integer> ldState = new MutableLiveData<>();
    public SelfApplyViewModel(@NonNull @NotNull Application application) {
        super(application);
    }
    public void getDataList(boolean isLoadMore, Map<String, Object> map){
        pageNum = isLoadMore ? pageNum + 1 : 1;
        map.put("page", pageNum);
        map.put("limit", 20);
        MerchantsNet.getInstance().getService().myApply(map).enqueue(new ICallBack<BaseEntity<ListResponse<List<ApplyEntity>>>>() {
            @Override
            public void onSuccess(BaseEntity<ListResponse<List<ApplyEntity>>> data) {
                if(data.isSuccess()){
                    ldData.postValue(data.getData().getList());
                }else{
                    ldData.postValue(new ArrayList<ApplyEntity>());
                }
            }
        });
    }

    /**
     * 获取投资项目下架删除状态
     * @param no
     */
    public void getState(Long no) {
        MerchantsNet.getInstance().getService().getProjectState(no).enqueue(new ICallBack<BaseEntity<Integer>>() {
            @Override
            public void onSuccess(BaseEntity<Integer> data) {
                if(data.isSuccess()){
                    ldState.postValue(data.getData());
                }
            }
        });
    }
}
